package storage

import org.iq80.leveldb._;
import org.fusesource.leveldbjni.JniDBFactory._;
import java.io._;

object dbtest {
  var db :DB = null;
  
  def main(args: Array[String]): Unit = {
    val leveldbOptions = new Options().createIfMissing(true)
    def leveldbfactory = factory;
    
		
		try {
			db = leveldbfactory.open(new File("/Users/jiangbuyun/leveldbdata/example"), leveldbOptions);
			
			db.put(bytes("Tampa"), bytes("rocks"));
			val value = asString(db.get(bytes("Tampa")));
			System.out.println("key="+"Tampa"+"\tvalue="+value);
			db.delete(bytes("Tampa"));
			val value1 = asString(db.get(bytes("Tampa")));
			System.out.println("key="+"Tampa"+"\tvalue="+value1);
		  
		}catch{
		   case e: NullPointerException => println(e.printStackTrace()); System.exit(-1) 
			 case unknown => println(unknown.printStackTrace()); System.exit(-1)
		}finally {
		  if(db != null){
			  try {
				db.close();
			} catch  {
				case unknown => println(unknown.printStackTrace()); System.exit(-1)
			}
		  }
		}

  }
}
